package br.com.investmenttracker.controller;

import java.util.List;

import javax.persistence.EntityManager;

import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.Validator;
import br.com.investmenttracker.dao.ProprietarioDao;
import br.com.investmenttracker.modelo.Proprietario;
import br.com.investmenttracker.modelo.Usuario;

@Resource
public class ProprietarioController {
	private Result result;
	private Validator validator;
	private EntityManager em;
	private ProprietarioDao dao;
	
	public ProprietarioController(EntityManager em,Result result, Validator validator, ProprietarioDao dao){
		this.result = result;
		this.validator = validator;
		this.em = em;
		this.dao = dao;
	}
	
	public void form(){
		
	}
	
	public List<Proprietario> listar(){
		
	}
	
	public void cadastrar(Proprietario proprietario){
		validator.validate(proprietario);
		validator.onErrorForwardTo(this).listar();	
		
		Usuario usuario = em.find(Usuario.class, Long.parseLong("2"));
		proprietario.setUsuario(usuario);
		em.persist(proprietario);
		result.redirectTo(this).listar();
	}
	
}
